package org.nobject.common.http;

import java.util.HashMap;
import java.util.Map;

import org.nobject.common.lang.IOUtils;
import org.nobject.common.lang.StringUtils;

/**
 * MIME工具类
 *
 * @author bianrongjun
 * @version 1.0
 */
public class MIMEUtils {
	
	/** mimes */
	private static Map mimes=new HashMap();
	
	static{
		try {
			String[] ss= IOUtils.getString(MIMEUtils.class.getResource("/org/nobject/common/http/mime.csv").openStream()).split("\n"); 
			for(String s:ss){
				String[] ks=s.split(",");
				if(mimes.containsKey(ks[0].trim())) continue;
				mimes.put(ks[0].trim(), ks[1].trim());
			}
		} catch (Exception e) {
			throw new RuntimeException("MIME读取失败");
		}
	}
	
	/**
	 * getMIMEByExtention
	 * @param ext
	 * @return
	 */
	public static String getMIMEByExtention(String ext){
		ext=StringUtils.removeStart(ext, ".");
		return (String)mimes.get(ext.toLowerCase());
	}
}
